package com.longyue.ms.app.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.longyue.ms.app.entity.CardRecord;
import com.longyue.ms.app.mapper.CardRecordMapper;
import com.longyue.ms.app.service.CardRecordService;
import com.longyue.ms.common.bean.AjaxResult;
import com.longyue.ms.common.bean.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Auther: Lisp
 * @Date: 2018/7/30 15:08
 * @Description:
 */
@Service
public class CardRecordServiceImpl implements CardRecordService {

    @Autowired
    private CardRecordMapper cardRecordMapper;


    @Override
    public AjaxResult insertRecord(CardRecord cardRecord) {
        // 保存维修记录
        cardRecordMapper.insertSelective(cardRecord);
        return AjaxResult.successResult();
    }

    @Override
    public Pagination<CardRecord> getPagedata(CardRecord cardRecord) throws Exception {
        PageHelper.startPage(cardRecord.getPageNum(), cardRecord.getPageSize());
        List<CardRecord> cardRecords = cardRecordMapper.getPagedata(cardRecord);
        return new Pagination<>(new PageInfo(cardRecords));
    }

    @Override
    public AjaxResult deleteById(Long id) {
        CardRecord cardRecord = cardRecordMapper.selectByPrimaryKey(id);
        cardRecord.setStatus(false);
        return cardRecordMapper.updateByPrimaryKeySelective(cardRecord) > 0 ? AjaxResult.successResult() : AjaxResult.errorResult("error");
    }

    @Override
    public CardRecord getById(Long id) {
        return cardRecordMapper.selectByPrimaryKey(id);
    }

    @Override
    public AjaxResult updateSupplier(CardRecord cardRecord) {
        return cardRecordMapper.updateByPrimaryKeySelective(cardRecord) > 0 ? AjaxResult.successResult() : AjaxResult.errorResult("error");
    }

    @Override
    public Map<Object, Object> getTotalMenyCount() {
        return cardRecordMapper.getTotalMenyCount();
    }
}
